/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.techshop.controller;

import com.techshop.model.PhoneCodeStore;
import com.techshop.model.Store;
import com.techshop.service.PhoneCodeStoreService;
import com.techshop.service.StoreService;
import java.util.List;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.SessionScoped;

/**
 *
 * @author Hai-PC
 */
@ManagedBean(name = "phoneCodeStoreController")
@SessionScoped
public class PhoneCodeStoreController extends AbstractController
{
    PhoneCodeStore selectedPhoneCodeStore = new PhoneCodeStore();
    private List<PhoneCodeStore> phoneCodeStoreList;
    private List<Store> storeList;
    private List<PhoneCodeStore> filterPhoneCodeStores;
    private Store selectedStore = new Store();
    private int selectedQuantity = 0;
    private boolean isSearch = false;
    
    @ManagedProperty(value = "#{phoneCodeStoreService}")
    private PhoneCodeStoreService phoneCodeStoreService;
    @ManagedProperty(value = "#{storeService}")
    private StoreService storeService;

    public void search()
    {
        isSearch = true;
        setPhoneCodeStoreList(phoneCodeStoreService.search(selectedStore.getId(), selectedQuantity));
    }

    public StoreService getStoreService() {
        return storeService;
    }

    public void setStoreService(StoreService storeService) {
        this.storeService = storeService;
    }

    public List<Store> getStoreList()
    {
        setStoreList(storeService.getAll());
        return storeList;
    }

    public void setStoreList(List<Store> storeList) {
        this.storeList = storeList;
    }
    
    public void resetSelectedPhoneCodeStore()
    {
        selectedPhoneCodeStore = new PhoneCodeStore();
    }

    public List<PhoneCodeStore> getPhoneCodeStoreList()
    {
        if (!isSearch)
        {
            setPhoneCodeStoreList(phoneCodeStoreService.getAll());
        }
        return phoneCodeStoreList;
    }

    public void setPhoneCodeStoreList(List<PhoneCodeStore> phoneCodeStoreList)
    {
        this.phoneCodeStoreList = phoneCodeStoreList;
    }

    public PhoneCodeStoreService getPhoneCodeStoreService()
    {
        return phoneCodeStoreService;
    }

    public void setPhoneCodeStoreService(PhoneCodeStoreService phoneCodeStoreService)
    {
        this.phoneCodeStoreService = phoneCodeStoreService;
    }

    public PhoneCodeStore getSelectedPhoneCodeStore()
    {
        return selectedPhoneCodeStore;
    }

    public void setSelectedPhoneCodeStore(PhoneCodeStore selectedPhoneCodeStore)
    {
        this.selectedPhoneCodeStore = selectedPhoneCodeStore;
    }

    public List<PhoneCodeStore> getFilterPhoneCodeStores()
    {
        return filterPhoneCodeStores;
    }

    public void setFilterPhoneCodeStores(List<PhoneCodeStore> filterPhoneCodeStores)
    {
        this.filterPhoneCodeStores = filterPhoneCodeStores;
    }

    public Store getSelectedStore() {
        return selectedStore;
    }

    public void setSelectedStore(Store selectedStore) {
        this.selectedStore = selectedStore;
    }

    public int getSelectedQuantity() {
        return selectedQuantity;
    }

    public void setSelectedQuantity(int selectedQuantity) {
        this.selectedQuantity = selectedQuantity;
    }
}